package beanLife;

import org.springframework.beans.factory.BeanNameAware;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;

//交给Spring管理
@Component
public class BeanLifeComponent implements BeanNameAware {
    //0.构造函数
    public BeanLifeComponent(){
        System.out.println("执行构造函数");
    }
    //1.实现这个接口：通知
    @Override
    public void setBeanName(String s) {
        System.out.println("设置了BeanName:"+s);
    }
    //2.设置前置方法
    @PostConstruct
    public void postConstruct(){
        System.out.println("执行postConstruct方法");
    }
//    这个方法不论是否执行，都会执行12步
    public void sayHello(){
        System.out.println("hello");
    }

    //3、init-method方法
    public void init(){
        System.out.println("执行init方法");
    }

    //4、销毁bean
    public void preDestroy(){
        System.out.println("执行了destroy方法");
    }
}
